//
//  xqzbViewController.m
//  PASystem
//
//  Created by michael on 16/9/28.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "xqzbViewController.h"
#import "PrepareModel.h"
#import "CompanyRecruitModel.h"
@interface xqzbViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,strong) UITableView *tab;
@property (nonatomic,strong) NSMutableArray *dataArray2;

@end

@implementation xqzbViewController

static NSString *const ID = @"CompanyRecruitCell";

-(NSMutableArray *)dataArray{
    
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

-(NSMutableArray *)dataArray2{

    if (_dataArray2 == nil) {
        _dataArray2 = [NSMutableArray array];
    }
    return _dataArray2;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed:241/255.0 green:242/255.0 blue:243/255.0 alpha:1];
    
    UITableView *tab1 = [[UITableView alloc] init];
    self.tab = tab1;
    tab1.delegate = self;
    tab1.dataSource = self;
    tab1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tab1];
    [tab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).mas_offset(10);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.view.mas_bottom).mas_offset(-148);
    }];

    [self loadData];

    [self loadData2];
}
- (void)loadData{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json  = [NSString stringWithFormat:@"{'action': xqzbhMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        if (JSON) {
            [self.dataArray removeAllObjects];
            NSDictionary *arr = JSON[@"reason"];
            NSDictionary *dict2 = arr[@"attrs"];
            if (dict2) {
                PrepareModel *model = [PrepareModel mj_objectWithKeyValues:dict2];
                [self.dataArray addObject:model];
                
            }
 
        }
        
        [self.tab reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
}

- (void)loadData2{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json  = [NSString stringWithFormat:@"{'action': zj1Mch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        if (JSON) {
            NSDictionary *arr = JSON[@"reason"];
            NSDictionary *dict2 = arr[@"attrs"];
            if (dict2) {
                CompanyRecruitModel *model = [CompanyRecruitModel mj_objectWithKeyValues:dict2];
                [self.dataArray2 addObject:model];
                
            }

        }
        [self.tab reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    PrepareModel *model = self.dataArray.firstObject;
    
    if (indexPath.row == 0) {
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10,80, 40)];
        
        label.text = @"会议标题:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        
        lbl2.text = model.TITLE;
        
        lbl2.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        return cell;
        
    }else if (indexPath.row == 1){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 60, 40)];
        
        label.text = @"主持人:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        
        lbl2.text = model.MASTER;
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
        
        
    }
    else if (indexPath.row == 2){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        
        label.text = @"会议时间:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        
        NSString *string = model.TIME;
        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
        fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
        fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
        NSDate *date = [fmt dateFromString:string];
        NSDateFormatter *fm = [[NSDateFormatter alloc] init];
        fm.dateFormat = @"yyyy-MM-dd";
        NSString *selfYear = [fm stringFromDate:date];
        lbl2.text = selfYear;
        
        lbl2.textAlignment = NSTextAlignmentRight;
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        
        return cell;
        
        
    }
    else if (indexPath.row == 3){
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10,80, 40)];
        
        label.text = @"参与人员:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        
        lbl2.text = model.JOINPERSON;
        
        lbl2.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        return cell;
        
    }
    else if (indexPath.row == 4){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        label.text = @"会议地点:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UILabel *lbl2 = [[UILabel alloc] init];
        
        lbl2.font = [UIFont systemFontOfSize:15];
        lbl2.textAlignment = NSTextAlignmentRight;
        lbl2.text = model.ADDRESS;
        [cell.contentView addSubview:lbl2];
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(label.mas_centerY);
            make.left.equalTo(label.mas_right);
            make.height.equalTo(label.mas_height);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
        }];
        
        return cell;
    }else if(indexPath.row == 5){
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        label.text = @"会议纪要:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UIWebView *lbl2 = [[UIWebView alloc] init];
        
        lbl2.backgroundColor = [UIColor whiteColor];
        
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.top.equalTo(cell.contentView.mas_top).mas_offset(10);
            make.left.equalTo(label.mas_right).mas_offset(5);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
            make.bottom.equalTo(cell.contentView.mas_bottom);
        }];
        
        //展会内容
        NSString *str = [model.SITUATION stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
        
        NSString *str2 = [str stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
        
        [lbl2 loadHTMLString:str2 baseURL:nil];
        
        return cell;
    
    }else{
        
        CompanyRecruitModel *model1 = self.dataArray2.firstObject;
        
        UITableViewCell* cell = [[UITableViewCell alloc]init];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 80, 40)];
        label.text = @"会议纪要:";
        
        label.font = [UIFont systemFontOfSize:15];
        
        [cell.contentView addSubview:label];
        
        UIWebView *lbl2 = [[UIWebView alloc] init];
        
        lbl2.backgroundColor = [UIColor whiteColor];
        lbl2.scrollView.scrollEnabled = NO;
        [cell.contentView addSubview:lbl2];
        
        [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(cell.contentView.mas_top).mas_offset(10);
            make.left.equalTo(label.mas_right).mas_offset(5);
            make.right.equalTo(cell.contentView.mas_right).mas_offset(-5);
            make.bottom.equalTo(cell.contentView.mas_bottom);
        }];
        
        //展会内容
        NSString *str = [model1.SITUATION stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
        
        NSString *str2 = [str stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
        
        [lbl2 loadHTMLString:str2 baseURL:nil];
        
        return cell;
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    PrepareModel *model = self.dataArray.firstObject;

    if (indexPath.row == 5) {
        //展会内容
        NSString *str = [model.SITUATION stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
        
        NSString *str2 = [str stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

        
        CGFloat H = [OAToolBox sizebyText:str2 font:15 minsWidth:20];
        
        return H + 50;
        
    }else if(indexPath.row == 6){
        CompanyRecruitModel *model1 = self.dataArray2.firstObject;

        //展会内容
        NSString *str = [model1.SITUATION stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
        
        NSString *str2 = [str stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

        CGFloat H = [OAToolBox sizebyText:str2 font:15 minsWidth:20];
        return H + 50;
    }else{
     
        return 60;
    }

}


@end












